const Controller = require('egg').Controller;

class BaseController extends Controller {
  get user() {
    return this.ctx.session.user;
  }

  success(data, message = '成功') {
    console.log('------------success中的数据------------');
    console.log(data);
    console.log('------------success中的数据------------');
    this.ctx.body = {
      code: 200,
      data,
      message,
    };
  }

  fail(data, message = '失败') {
    console.log('------------fail中的数据------------');
    console.log(data);
    console.log('------------fail中的数据------------');
    this.ctx.body = {
      code: 500,
      data,
      message,
    };
  }

  notFound(msg) {
    msg = msg || 'not found';
    this.ctx.throw(404, msg);
  }
}
module.exports = BaseController;
